package com.lzq.mq.broker.config;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 通用线程池配置
 */
public class CommonThreadPoolConfig {

    /**
     * MQ的topic信息刷盘线程池, 用于将mq的topic信息周期性刷入磁盘
     */
    public static ThreadPoolExecutor refreshMqTopicExecutor = new ThreadPoolExecutor(
            1,
            1,
            30,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(10),
            (r) -> {
                Thread thread = new Thread(r);
                thread.setName("refresh-eagle-mq-topic-thread");
                return thread;
            }
    );

    /**
     * 队列偏移量刷盘线程池, 用于将队列偏移量周期性刷入磁盘
     */
    public static ThreadPoolExecutor refreshConsumeQueueOffsetExecutor = new ThreadPoolExecutor(
            1,
            1,
            30,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(10),
            (r) -> {
                Thread thread = new Thread(r);
                thread.setName("refresh-consume-queue-offset-thread");
                return thread;
            }
    );
}
